<template>
  <div>
    <TopFilter :list="topFilterList" :collapse="false" @filterChange="changeHandle"
               @onCollapse="collapseHandle"></TopFilter>
    <FilterTable
      selectionType="single"
      ref="table" :columns="columns" :fetchapi="fetchApi" :params="fetchParams" datakey="records"
      :onColumnsChange="columns => (this.columns = columns)"
      :onSyncTableData="tableChangeFun"
      :onRowSelectChange="selectChange"
    >
    </FilterTable>

    <div class="dialogBottmView">
      <el-button size="small" type="primary" class="btnStyle" @click="submitBtn">确定
      </el-button>
      <el-button size="small" type="primary" class="btnStyle" @click="closeDialog">取消
      </el-button>
    </div>

  </div>
</template>

<script>
  import {mapState} from 'vuex';
  import {dictionary} from '@/utils/dictMixin';
  import moment from 'moment';
  import {getTmPartFacList, queryUnitCode} from '@/api/repair/batchEventManagement/activityDistribution';

  export default {
    name: 'addVin',
    components: {},
    mixins: [dictionary],
    data()
    {
      this.BaseTable = null;
      return {
        topFilterList: this.createTopFilterList(),
        visible: false,
        fetchApi: getTmPartFacList,
        fetchParams: {},
        columns: this.createTableColumns(),
        selectArr: []
      };
    },
    props: [],
    components: {},

    mounted()
    {
      this.BaseTable = this.$refs.table.$refs.pageTable;
      this.getUnit();
    },
    methods: {

      async getUnit()
      {
        const res = await queryUnitCode();
        this.columns.find(item => item.dataIndex === 'unit').dictItems = res.data.map(x => ({
          text: x.UNIT_NAME,
          value: x.UNIT_CODE
        }));
      },

      tableChangeFun(val)
      {
      },
      selectChange(val)
      {
        this.selectArr = val
        console.log(val)
      },

      createTableColumns()
      {
        return [
          {
            title: '序号',
            dataIndex: 'index',
            width: 70,
            sorter: true,
            render: props =>
            {
              return <span>{props.row.index + 1}</span>;
            }
          },
          {
            title: '配件代码',
            dataIndex: 'partCode',
            width: 150,
            sorter: true,
            filter: true,
            filterType: 'input',
          },
          {
            title: '配件名称',
            dataIndex: 'partName',
            width: 150,
            sorter: true,
            filter: true,
            filterType: 'input',
          },
          {
            title: '单位',
            dataIndex: 'unit',
            width: 150,
            sorter: true,
            filter: true,
            filterType: 'input',
            dictItems: []
          },

          {
            title: '数量',
            dataIndex: 'counts',
            sorter: true,
            filter: true,
            filterType: 'input'

          },
          {
            title: '索赔单价',
            dataIndex: 'price',
            sorter: true,
            filter: true,
            filterType: 'input'

          },

        ];
      },
      createTopFilterList()
      {
        return [
          {
            type: 'INPUT',
            label: '配件代码',
            fieldName: 'partCode',
            placeholder: '配件代码...'
          },
          {
            type: 'INPUT',
            label: '配件名称',
            fieldName: 'partName',
            placeholder: '配件名称...'
          },

        ];
      },

      collapseHandle()
      {
        this.$nextTick(() =>
        {
          this.BaseTable.EXECUTE_RESET_HEIGHT();
        });
      },

      changeHandle(val)
      {
        // val.bDate=moment(val['bDate']).format('YYYY-MM-DD')
        // val.eDate=moment(val['eDate']).format('YYYY-MM-DD')
        this.fetchParams = Object.assign({}, val);

        console.log(this.fetchParams)
      },

      closeDialog()
      {
        this.$emit('close')
      },
      submitBtn()
      {
        if (this.selectArr.length == 0)
        {
          this.$notify.warning({title: '提示信息', message: '请您选择配件'});
          return
        }
        this.$emit('selectArr', this.selectArr)
      }
    }
  };
</script>

<style lang="less" scoped>
  .bg1 {
    border: 1px solid @borderColor;
    border-radius: @borderRadius;
    box-shadow: @boxShadow;
    padding: @modulePadding;
    padding-left: 0;
    padding-top: 15px;
    padding-bottom: 15px;
  }

  .bg2 {
    margin-top: 10px;
    margin-bottom: 10px;
  }

  .btn {
    text-align: center;
  }

  .btnStyle {
    margin-top: 10px;
  }

</style>
